package com.example.controller;

import com.example.common.bean.ApiResult;
import com.example.config.aop.PostCount;
import com.example.modules.dto.CommentDTO;
import com.example.modules.dto.PostDTO;
import com.example.service.CommentService;
import com.example.service.PostPopularService;
import com.example.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "帖子评论")
@RequestMapping("/api")
public class PostControlelr {
    @Autowired
    private PostService postService;
    @Autowired
    private PostPopularService postPopularService;
    @Autowired
    private CommentService commentService;

    @ApiOperation("新增帖子")
    @PostMapping("/post")
    public ApiResult insertPost(@Validated @RequestBody PostDTO postDTO){
        return postService.insertPost(postDTO);
    }

    @ApiOperation("查看帖子")
    @PostCount(operateContent = "detailPost")
    @GetMapping("/detailPost/{id}")
    public ApiResult detailPost(@ApiParam(value = "id",required = true)@PathVariable("id") Integer id){
        return postService.detailPost(id);
    }

    @ApiOperation("发表评论")
    @PostMapping("/comment")
    public ApiResult insertComment(@Validated @RequestBody CommentDTO commentDTO){
        return commentService.insertComment(commentDTO);
    }

    @ApiOperation("根据帖子ID查询评论信息")
    @GetMapping("/detailComment/{postId}")
    public ApiResult datailComment(@ApiParam(value = "帖子id",required = true)@PathVariable("postId")Integer postId,
                                   @ApiParam(value = "页码",required = true)@RequestParam("pageNum") Integer pageNum,
                                   @ApiParam(value = "页码",required = true)@RequestParam("pageSize")Integer pageSize){
        return commentService.datailComment(postId,pageNum,pageSize);
    }

    @ApiOperation("根据帖子id删帖子")
    @DeleteMapping("/deletePost/{postId}")
    public ApiResult deletePostByPostId(@ApiParam(value = "帖子id",required = true)@PathVariable("postId") Integer postId){
        return postService.deletePostByPostId(postId);
    }

    @ApiOperation("根据评论id删除评论")
    @DeleteMapping("/deleteComment/{id}")
    public ApiResult deleteCommentById(@ApiParam(value = "id",required = true)@PathVariable("id") Integer id){
        return commentService.deleteCommentById(id);
    }

    @ApiOperation("查询我的帖子")
    @GetMapping("/getMyPost")
    public ApiResult getMyPost(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer userId){
        return postService.getMyPost(userId);
    }

    @ApiOperation("查询我评论的帖子")
    @GetMapping("/getMyCommentPost")
    public ApiResult getMyCommentPost(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer userId){
        return postService.getMyCommentPost(userId);
    }

    @ApiOperation("查询所有对我帖子的评论")
    @GetMapping("/getMyPostComment")
    public ApiResult getMyPostComment(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer userId){
        return postService.getMyPostComment(userId);
    }

    @ApiOperation("查询所有对我帖子的评论数")
    @GetMapping("/getMyPostCommentTotal")
    public ApiResult getMyPostCommentTotal(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer userId){
        return commentService.getMyPostCommentTotal(userId);
    }

    @ApiOperation("查询对我评论的回复")
    @GetMapping("/getReplyMyComments")
    public ApiResult getReplyMyComments(@ApiParam(value = "用户id",required = true)@RequestParam("userId") Integer userId){
        return commentService.getReplyMyComments(userId);
    }
}
